package com.sky.mapper;

import com.sky.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;

@Mapper
public interface UserMapper {
  /**
   * 添加微信用户
   * @param user
   */
  @Insert("insert into user (openid, name, phone, sex, id_number, avatar, create_time) VALUES " +
      "(#{openid}, #{name}, #{phone}, #{sex}, #{idNumber}, #{avatar}, #{createTime})")
  @Options(useGeneratedKeys = true, keyProperty = "id")  // 这会自动将生成的id赋值给 User 对象的 id 属性
  void insert(User user);
  
  /**
   * 根据openid查询用户
   * @param openid
   */
  @Select("select * from user where openid = #{openid}")
  User findUserByOpenId(String openid);
  
  /**
   * 按用户的ID 查找用户。
   */
  @Select("select * from user where id = #{userId}")
  User findUserByUserId(Long userId);
}
